<html>
<head><meta charset="utf-8"><title>pub macro vs macro_rules! · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/pub.20macro.20vs.20macro_rules!.html">pub macro vs macro_rules!</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="182702594"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/pub%20macro%20vs%20macro_rules%21/near/182702594" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> yunhua <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/pub.20macro.20vs.20macro_rules!.html#182702594">(Dec 05 2019 at 20:55)</a>:</h4>
<p>Hi there are some macro using pub macro, such as <br>
src/libcore/marker.rs <br>
pub macro Copy($item:item) { /* compiler built-in */ }<br>
what is the difference "pub macro" compare with macro_rules!, there are lots of information for macro_rules!, but I can't find related information for "pub macro", Thanks!</p>



<a name="182705649"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/pub%20macro%20vs%20macro_rules%21/near/182705649" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/pub.20macro.20vs.20macro_rules!.html#182705649">(Dec 05 2019 at 21:21)</a>:</h4>
<p><a href="https://rust-lang.github.io/rfcs/1561-macro-naming.html" target="_blank" title="https://rust-lang.github.io/rfcs/1561-macro-naming.html">https://rust-lang.github.io/rfcs/1561-macro-naming.html</a> and <a href="https://rust-lang.github.io/rfcs/1584-macros.html" target="_blank" title="https://rust-lang.github.io/rfcs/1584-macros.html">https://rust-lang.github.io/rfcs/1584-macros.html</a> give a bit of background</p>



<a name="182705972"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/pub%20macro%20vs%20macro_rules%21/near/182705972" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Matthew Jasper <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/pub.20macro.20vs.20macro_rules!.html#182705972">(Dec 05 2019 at 21:24)</a>:</h4>
<p>In short the differences are:</p>
<ul>
<li>Normal item scoping and privacy rules</li>
<li>Full hygiene</li>
<li>A short syntax when there's only a single case</li>
<li><code>,</code> vs. <code>;</code> as the separator between cases</li>
</ul>
<p>Notably a <code>pub macro</code> doesn't end up at the crate root, unlike a <code>#[macro_export] macro_rules!</code></p>



<a name="182707543"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/pub%20macro%20vs%20macro_rules%21/near/182707543" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> yunhua <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/pub.20macro.20vs.20macro_rules!.html#182707543">(Dec 05 2019 at 21:39)</a>:</h4>
<p>Thanks! <span class="user-mention" data-user-id="116118">@Matthew Jasper</span></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>